<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <title>weixin api test</title>
    <link rel="stylesheet" href="../jslib/jquery-mobile/jquery.mobile-1.4.5.min.css">
    <script src="../jslib/jquery/jquery-2.1.4.min.js"></script>
    <script src="../jslib/jquery-mobile/jquery.mobile-1.4.5.min.js"></script>
    <script src="../jslib/jquery/jquery.url.js"></script>
    <script src="../jslib/ukulele/ukulele.js"></script>
</head>

<body uku-application>
    <div data-role="page">
        <div data-role="header">
            <h1>weixin api test</h1>
        </div>
        <div role="main" class="ui-content">
            <div>
                <img uku-src="myCtrl.userInfo.headimgurl" style="width:46px;float:left"/>
                <h4 style="float:left;padding-left:10px;vertical-align: middle;">{{myCtrl.userInfo.nickname}}</h4>
                <h4 style="float:left;padding-left:10px;vertical-align: middle;">, welcome!</h4>
                <div style="clear:both"/>
            </div>
            <button class="ui-btn" uku-onclick="myCtrl.createActivity()">Create Test Activity</button>
            <button class="ui-btn" uku-onclick="myCtrl.join()">Join Activity</button>
        </div>
    </div>
</body>
<script>
    function MyController() {
        this.openid = undefined;
        this.userInfo = undefined;
        var self = this;
        this.getUserInfo = function (openid) {
            var url = "/user/" + openid;
            $.get(url, function (data) {
                self.userInfo = data;
            }).error(function(){
                console.error("get user error");
            });
        };
        this.join = function () {
            
        };
		this.createActivity = function(){
			$.post("/activity",null,function(data){
				alert(data);
			});
		};
    }
    $(document).ready(function () {
        var uku = new Ukulele();
        var myCtrl = new MyController();
        uku.registerController("myCtrl", myCtrl);
        uku.init();
        myCtrl.openid = jQuery.url.param("openid");
        myCtrl.getUserInfo(myCtrl.openid);
    });
</script>

</html>